草庐IT

c++ - 在库 API 中传递 std::string

全部标签

go - 用于在 etcd 集群中查找 key 的 API

我正在尝试编写一段代码,我需要在其中查找某个key是否存在于etcd中。我试过这个:_,err=kapi.Get(context.Background(),key,nil)iferr!=nil{returnerr}else{...但即使键不在集群中,错误也总是nil。知道我在这里做错了什么吗?或者是否有任何其他API调用? 最佳答案 如果你在这里使用goclientv3KV客户端:https://godoc.org/go.etcd.io/etcd/clientv3#KV它返回以下类型:https://godoc.org/go.etc

go - 如何将结构作为参数传递给 xml-rpc

我有点新手,一直在尝试使用我的goAPI中的XML-RPC方法,为此我选择了https://github.com/mattn/go-xmlrpc一切正常,直到我不得不将结构作为参数传递。在我得到的结构的示例中,格式为python字典{string:string}或空字典。如果我为结构提供我在python示例中使用的值,我将得到panicserving。我试图创建映射或空结构,但它会说给定的参数是错误的(错误是由xml-rpc引起的)。如果我尝试将其转换为json并使用编码/json解码器将其解析回来,它会说我使用了错误的结构。typeDatastruct{serial_numberst

api - slice ,groupBy []数组

我已经通过[]数组解决了所有服务器问题。问题是如何slice(groupBy)状态,可启动。我只想接受status=available,bootable=falseControllerslicedBy:=make(map[string]interface{})server:=blockstorage.ListVolumes(tenantID.(string))Json数组{id123statusavailablebootablefalse...}作为数组的服务器[{"id":"a8b123fc-a141-4682-b65b-d56899621959","status":"availab

go - json 字符串不会用 json api.Unmarshal Payload 解码

关闭。这个问题是notreproducibleorwascausedbytypos.它目前不接受答案。这个问题是由于错别字或无法再重现的问题引起的。虽然类似的问题可能是on-topic在这里,这个问题的解决方式不太可能帮助future的读者。关闭3个月前。Improvethisquestion我正在尝试解码一个简单的jason字符串:typeCitystruct{IDint`jsonapi:"primary,cities"`CountryCodestring`jsonapi:"attr,countryCode"`Namestring`jsonapi:"attr,name"`}funcT

go - 如何在 computeService.Zones.List(project) Google Cloud Platform API 中添加过滤器

我正在尝试在GoogleCloudPlatformAPI中过滤区域列表但我无法在Google中找到任何说明在API中放置过滤器的文档:req:=computeService.Zones.List(project)上面的代码行将列出GoogleCloudCompute中的区域在命令行中我们可以做同样的事情gcloudcomputezoneslist--filter="name:us-"谢谢,席德 最佳答案 它会在以下情况下帮助某人:req:=computeService.Zones.List("ProjectName")iferr:=

go - 如何将标志变量传递给 Golang 中的 http.Get

我有一段代码,它对我正在使用的RESTAPI所需的URL进行硬编码。我想做的是,使用这两个标志动态生成URL。例如,效果如下:响应,错误:=http.Get("https://swapi.co/api/%s/1",resourcePtr)我目前的代码如下:funcmain(){resourcePtr:=flag.String("resource","","astring")idPtr:=flag.Int("id",1,"anint")flag.Parse()response,err:=http.Get("https://swapi.co/api/planets/1")iferr!=ni

go - 从 golang 代码向 Google Drive API 发送文件产生错误 : Unsupported content with type: image/jpeg

基于GoogleDriveAPIdocs上传文件的正确方法是:curl-v-H'Authorization:Bearermytoken'-F'metadata={"name":"test3.jpeg"};type=application/json'-Ffile=@jpeg_image.jpeg'https://www.googleapis.com/upload/drive/v3/files?uploadType=multipart'现在,我需要从golang代码执行相同的请求,但我很难将其转换为golang,这是我在多次尝试后使用的代码://fileBytesareoftype[]by

go - 如何在没有指数的情况下从 json 的 map[string]interface{} 格式化 int 数字?

此演示:https://play.golang.org/p/7tpQNlNkHgGpackagemainimport("fmt""encoding/json")funcmain(){jsonStr:=`{"code1":10080061,"code2":12.2}`data:=map[string]interface{}{}json.Unmarshal([]byte(jsonStr),&data)fork,v:=rangedata{fmt.Printf("%v:%v,%v:%f,%v:%.0f\n",k,v,k,v,k,v)}}输出:code1:1.0080061e+07,code1:

go - 如何为 []map[string]string 添加示例

我使用了https://github.com/swaggo/swag库自动生成api文档。我有一个数据类型[]map[string]string,我应该如何添加示例?我检查了文档,但现在显示类型[]map[string]string。文档站点:https://github.com/swaggo/swagtypeUploadReqstruct{FilesM[]map[string]string`form:"files"json:"files"binding:"required"example:"TODO"`Tagstring`form:"tag"json:"tag"binding:"re

string - 附加到二维字符串 slice 时的奇怪行为

Thisquestionalreadyhasanswershere:Golangslicereferenceconfusion(3个答案)去年关闭。我正在尝试在Go中实现堆的置换算法。它应该返回给定输入集的所有可能的排列。funcPermute(in[]string)[][]string{c:=make([]int,len(in))out:=make([][]string,0)fori:=rangeout{out[i]=make([]string,0)}fmt.Println(in)out=append(out,in)i:=0foriPrintln语句显示预期的输出。返回的out值具有